import { Component, Vue } from 'vue-property-decorator'

@Component({
  created() {
    if ((this.$options as any).sockets) {
      (this.$options as any).sockets.onmessage = (data) => this.socketGetMessage(data)
    }
  },
  destroyed() {
    delete this.$options.sockets.onmessage
  }
})
export default class SocketsMixin extends Vue {
  get getSocket(): any {
    return (this as any).$socket
  }

  /**
   * 这个方法进行重写
   * @param messageEvent
   */
  public socketGetMessage(messageEvent: MessageEvent) {

  }

  /**
   * 这个方法进行调用
   * @param message
   */
  public socketSendMessage(message: string) {
    this.getSocket.send(message)
  }
}
